package com.yunmai11.yunmai.fragment;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;

import com.yunmai11.yunmai.R;
import com.yunmai11.yunmai.activity.WebViewActivity;
import com.yunmai11.yunmai.adapter.GridRecyclerViewAdapter;
import com.yunmai11.yunmai.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/1/15.
 */
public class ChatFragment extends BaseFragment {
    private RecyclerView rv_grid;
    private GridRecyclerViewAdapter mAdapter;
    private List<String> mdatas;

    @Override
    protected View initView() {
        genData();
        mAdapter = new GridRecyclerViewAdapter(getActivity(), mdatas);
        mAdapter.setItemClickListener(new GridRecyclerViewAdapter.MyGridItemOnClickListener() {
            @Override
            public void onClick(View v, int position) {
                switch (position) {
                    case 0:
                        Intent webViewIntent = new Intent(getActivity(), WebViewActivity.class);
                        startActivity(webViewIntent);
                    break;
                    case 1:
                        Uri uri = Uri.parse("http://baidu.com");
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                        break;
                    case 2:

                        break;
                    case 3:

                        break;
                }
                CommonUtils.showToast(getActivity(), "click->"+position);
            }

            @Override
            public void onLongClick(View v, int position) {
                CommonUtils.showToast(getActivity(), "long click->"+position);
            }
        });

        View v = LayoutInflater.from(mContext).inflate(R.layout.chat_fragment, null);
        rv_grid = (RecyclerView) v.findViewById(R.id.rv_grid);
        rv_grid.setAdapter(mAdapter);
        rv_grid.setLayoutManager(new GridLayoutManager(getActivity(), 3));
        rv_grid.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
        return v;
    }

    /**
     * 生成模拟数据
     */
    private void genData() {
        mdatas = new ArrayList<String>();
        mdatas.add("WebView");
        mdatas.add("浏览器");
        mdatas.add("PHP");

        for (int i=0;i<3;i++) {
            mdatas.add("项目-"+i);
        }
    }

    @Override
    protected void initData() {
        super.initData();
    }
}
